package com.kltn.zigo.data.adapter;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.kltn.zigo.R;
import com.kltn.zigo.data.IP;
import com.kltn.zigo.data.loader.CommentUserLoader;
import com.kltn.zigo.process.ImageLoader;

public class CommentUserAdapter extends BaseAdapter{
	private Activity activity;
    private ArrayList<HashMap<String, String>> data;
    private static LayoutInflater inflater=null;
    private CommentUserLoader commentuserloader;
    public ImageLoader imageLoader; 
    
    public CommentUserAdapter(Activity a, CommentUserLoader pl) {
        activity = a;
        data=pl.GetCommentUser();
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageLoader=new ImageLoader(activity.getApplicationContext());
        commentuserloader = pl;        
    }
    
    public CommentUserAdapter(Activity a, CommentUserLoader pl, ArrayList<HashMap<String, String>> d) {
        activity = a;
        data=d;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageLoader=new ImageLoader(activity.getApplicationContext());
        commentuserloader = pl;  
    }

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View vi=convertView;
        if(convertView==null)
            vi = inflater.inflate(R.layout.item_list_comment, null);

        TextView userid = (TextView)vi.findViewById(R.id.tvUserID);
        TextView placeid = (TextView)vi.findViewById(R.id.tvPlaceID);
        TextView username = (TextView)vi.findViewById(R.id.tvUsername);
        TextView typecomment = (TextView)vi.findViewById(R.id.tvTypeComment);
        TextView placename = (TextView)vi.findViewById(R.id.tvPlaceName);
        TextView placeaddress = (TextView)vi.findViewById(R.id.tvPlaceAddress);
        TextView detailcomment = (TextView)vi.findViewById(R.id.tvComment);
        ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image); 
        
        HashMap<String, String> commentuser = new HashMap<String, String>();
        commentuser = data.get(position);
        // Setting all values in listview
        userid.setText(commentuser.get(commentuserloader.TAG_USER_ID));
        placeid.setText(commentuser.get(commentuserloader.TAG_PLACE_ID));
        username.setText(commentuser.get(commentuserloader.TAG_USER_NAME));
        placename.setText(commentuser.get(commentuserloader.TAG_PLACE_NAME));
        placeaddress.setText(commentuser.get(commentuserloader.TAG_PLACE_ADDRESS) + "-" + commentuser.get(commentuserloader.TAG_PLACE_DISTRICT)
        													+ "-" + commentuser.get(commentuserloader.TAG_PLACE_PROVINCE));
        detailcomment.setText(commentuser.get(commentuserloader.TAG_DETAIL_COMMENT));
        if(commentuser.get(commentuserloader.TAG_COMMENT_TYPE).equals("1"))
        	typecomment.setText("bình luận");
        else if(commentuser.get(commentuserloader.TAG_COMMENT_TYPE).equals("2"))
        	typecomment.setText("chia sẻ"); 
        else if(commentuser.get(commentuserloader.TAG_COMMENT_TYPE).equals("3"))
        	typecomment.setText("tạo trên ZiGo");
        else if(commentuser.get(commentuserloader.TAG_COMMENT_TYPE).equals("4"))
        	typecomment.setText("cập nhật thông tin");       	
        String Url_avatar = IP.get_IP() + IP.get_path_avatar() + commentuser.get(commentuserloader.TAG_NAME_AVATAR);
        imageLoader.DisplayImage(Url_avatar , thumb_image);
        return vi;
	}
}
